package com.xuyuan.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xuyuan.spring.aop.AfterResponse;
import com.xuyuan.spring.event.CustomMyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;


@Service
public class MyServiceImpl implements MyService {
    @Autowired
    private ObjectMapper mapper;

    @Override
    @AfterResponse
    public String getName(Boolean flag) {
        return "xuyuan";
    }

    @EventListener(CustomMyEvent.class)
    public void onCustomMyEvent(CustomMyEvent event) {
        JsonNode jsonNode = mapper.convertValue(event.getSource(), JsonNode.class);
        System.out.println(jsonNode.get("email").asText() + jsonNode.get("message").asText());
    }
}
